#include "port.h"

void step_motor_cotor(unsigned char step, unsigned char dir){
    int tmp_step = step;
    if(0 == dir){
        tmp_step = 7-step;
    }

    switch (tmp_step)
    {
    case 0: M_1_A = 1; M_2_B = 0; M_3_C = 0; M_4_D = 0; break;
    case 1: M_1_A = 1; M_2_B = 1; M_3_C = 0; M_4_D = 0; break;
    case 2: M_1_A = 0; M_2_B = 1; M_3_C = 0; M_4_D = 0; break;
    case 3: M_1_A = 0; M_2_B = 1; M_3_C = 1; M_4_D = 0; break;
    case 4: M_1_A = 0; M_2_B = 0; M_3_C = 1; M_4_D = 0; break;
    case 5: M_1_A = 0; M_2_B = 0; M_3_C = 1; M_4_D = 1; break;
    case 6: M_1_A = 0; M_2_B = 0; M_3_C = 0; M_4_D = 1; break;
    case 7: M_1_A = 1; M_2_B = 0; M_3_C = 0; M_4_D = 1; break;
    default: break;
    }
}

void step_motor_cotor_1(unsigned char step, unsigned char dir){
    int tmp_step = step;
    if(0 == dir){
        tmp_step = 7-step;
    }

    switch (tmp_step)
    {
    case 0: M_1_A = 0; M_2_B = 0; M_3_C = 0; M_4_D = 1; break;
    case 1: M_1_A = 0; M_2_B = 0; M_3_C = 1; M_4_D = 1; break;
    case 2: M_1_A = 0; M_2_B = 0; M_3_C = 1; M_4_D = 0; break;
    case 3: M_1_A = 0; M_2_B = 1; M_3_C = 1; M_4_D = 0; break;
    case 4: M_1_A = 0; M_2_B = 1; M_3_C = 0; M_4_D = 0; break;
    case 5: M_1_A = 1; M_2_B = 1; M_3_C = 0; M_4_D = 0; break;
    case 6: M_1_A = 1; M_2_B = 0; M_3_C = 0; M_4_D = 0; break;
    case 7: M_1_A = 1; M_2_B = 0; M_3_C = 0; M_4_D = 1; break;
    default: break;
    }
}


void step_motor_run(){
    unsigned char i = 0;
    for(i = 0; i < 8; i++){
        delay_ms(1);
        step_motor_cotor(i, 1);
        // step_motor_cotor_1(i, 1);
    }
}

int main(){
    
    while(1)
    {
        step_motor_run();
    }
    return 0;
}